package br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.util.locking;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo;
import br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.util.Masker;
import br.edu.ufcg.lsd.wbis.ui.client.ui.management.PanelManager;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.widgets.MessageBox;

/**
 * @author Renato Miceli
 */
public class UnlockingLoginCallback implements AsyncCallback<UserInfo> {

	private final PanelManager panelManager;
	private final UnlockingWindow unlockingWindow;

	/**
	 * @param unlockingWindow
	 * @param panelManager
	 */
	public UnlockingLoginCallback(UnlockingWindow unlockingWindow, PanelManager panelManager) {
		this.unlockingWindow = unlockingWindow;
		this.panelManager = panelManager;
	}

	/**
	 * {@inheritDoc}
	 */
	public void onFailure(Throwable caught) {
		MessageBox.alert("Password error", "The typed password does not match!");
	}

	/**
	 * {@inheritDoc}
	 */
	public void onSuccess(UserInfo result) {
		this.unlockingWindow.destroy();
		Masker masker = new Masker(this.panelManager.getCurrentPanel());
		masker.unmask();
		this.panelManager.getInfoManager().setInfo(result);
	}

}
